<script type="text/javascript">
	function doSearchDevice(value) {
		
	}
	
	//表格查询  
	function reloadDevice() {
		var params = device_list.datagrid('options').queryParams; //先取得 datagrid 的查询参数  
		printLog(params);
		device_list.datagrid('reload'); //设置好查询参数 reload 一下就可以了  
		device_list.datagrid('unselectAll');
		device_list.datagrid('uncheckAll');
	}


	function addDevice() {
		createFromWindow("新增信息", "device.do?editDevice", "device.do?saveDevice",
				function(data) {
					reloadDevice();
				});
	}
	
	function deleteDevice() {
		var rows = device_list.datagrid('getChecked');
	    if (rows&&rows.length>0){
	        $.messager.confirm('询问','你确认要删除吗?',function(r){
	            if (r){
	            	var ids = "";
	            	for(var i=0; i<rows.length; i++){
	            		ids += rows[i].id+",";
	            	}
	                $.post('device.do?deleteDeviceItems',{ids:ids},function(result){
	                    if (result.success){
	                    	reloadDevice();    
	                    }
	                    showMsg(result.msg);
	                },'json');
	            }
	        });
	    }else {
	    	showMsg("请选择操作记录.");
	    }
	}
	
	function syncDeviceTime() {
		var rows = device_list.datagrid('getChecked');
	    if (rows&&rows.length>0){
	        $.messager.confirm('询问','你确认要同步设备时间吗?',function(r){
	            if (r){
	            	var sns = "";
	            	for(var i=0; i<rows.length; i++){
	            		sns += rows[i].sn+",";
	            	}
	            	onLoadingHandler(function() {
// 	            		 $.post('devOperation.do?syncDeviceTime',{sns:sns},function(result){
// 	 	                    showMsg(result.msg);
// 	 	                 },'json');
	            		 $.ajax({  
	            	         type : "post",  
	            	         url : 'devOperation.do?syncDeviceTime',  
	            	         data : {sns:sns},  
	            	         dataType : "json", 
// 	            	         async : false,  
	            	         success : function(result){  
	            	        	showMsg(result.msg);  
	            	        	removeload();
	            	         }  
	            	     }); 
	            	});
	               
	            }
	        });
	    }else {
	    	showMsg("请选择操作记录.");
	    }
	}

	function editDevice() {
		var rows = device_list.datagrid('getChecked');
		printLog(rows);
		if (rows&&rows.length>0) {
			if(rows.length>1) {
				showMsg('请选择一条操作记录.');
				return;
			}
			createFromWindow("编辑信息", "device.do?editDevice&deviceId=" + rows[0].id,
					"device.do?saveDevice", function(data) {
						reloadDevice();
					},true);
		} else {
			showMsg('请选择操作记录.');
		}

	}
	
	
	//操作按钮触发
	function operationsLookDevice(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = device_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			createFromWindow("查看信息", "device.do?editDevice&deviceId=" + id,
					null, null,false);
		} else {
			showMsg('请选择查看记录.');
		}
	}
	
	function operationsEditDevice(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = device_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			createFromWindow("编辑信息", "device.do?editDevice&deviceId=" + id,
					"device.do?saveDevice", function(data) {
						reloadDevice();
					},true);
		} else {
			showMsg('请选择编辑记录.');
		}
	}
	
	function operationsSendDevice() {
		printLog('发送');
	}
	
	function operationsDeleteDevice(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = new_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			$.messager.confirm('询问', '你确认要删除吗?', function(r) {
				if (r) {
					$.post('device.do?deleteDeviceItems', {
						ids : id
					}, function(result) {
						if (result.success) {
							reloadDevice(); 
						}
						showMsg(result.msg);
					}, 'json');
				}
			});
		} else {
			showMsg("请选择操作记录.");
		}
	}
	
	function clearDeviceSearch() {
		setGridSearchParams('device_list','deviceSearchForm',true,reloadDevice);
	}
	
	//根据条件查询设备
	function deviceSearch() {
		setGridSearchParams('device_list','deviceSearchForm',false,reloadDevice);
	}
</script>

<#assign operations = "[\{shiro:'hotel:device:refresh',onClick:'operationsLookDevice',src:'static/jmax/images/notes/note.png',title:'查看'},
	   					\{shiro:'hotel:device:edit',onClick:'operationsEditDevice',src:'static/jmax/images/notes/note_edit.png',title:'编辑'},
	   					\{shiro:'hotel:device:delete',onClick:'operationsDeleteDevice',src:'static/jmax/images/notes/note_delete.png',title:'删除'}
	  				   ]"/>

<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'center',border:false">
		
		<@eu.datagrid id="device_list" toolbar="#devicelist_search" idField="id" operations="${operations!}"
			 url="device.do?loadList" rownumbers="true"
			 item="com.xdtech.hotel.vo.DeviceItem"/>
		
		<div id="devicelist_search">
			<div style="margin-bottom:5px;padding-left:5px;margin-top: 5px;">
				<form id="deviceSearchForm">
					<table>
						<tr>
							<td>设备SN号：</td>
							<td><input type="text" name="sn" style="width: 150px" /></td>
							<td>IP地址：</td>
							<td>
								<input type="text" name="ip" style="width: 150px" />
							</td>
							<td>
								<@eu.linkbutton showName="查询" iconCls="icon-search" onclick="deviceSearch()"/>
	 					 		<@eu.linkbutton showName="清空" iconCls="icon-clear" onclick="clearDeviceSearch()"/>
 					 		</td>
						</tr>
					</table>
				</form>
				
			</div>
			<div id="device_toolbar" style="height: auto">
				<@eu.linkbutton showName="新增" shiro="hotel:device:add" iconCls="icon-add" onclick="addDevice()"/>
				<@eu.linkbutton showName="删除" shiro="hotel:device:delete" iconCls="icon-remove" onclick="deleteDevice()"/>
				<@eu.linkbutton showName="编辑" shiro="hotel:device:edit" iconCls="icon-edit" onclick="editDevice()"/>
				<@eu.linkbutton showName="同步时间" shiro="hotel:device:syncTime" iconCls="icon-time-go" onclick="syncDeviceTime()"/>
				<@eu.linkbutton showName="刷新" shiro="hotel:device:refresh" iconCls="icon-reload" onclick="reloadDevice()"/>
				
			</div>
		</div>
	</div>
</div>